#!/bin/bash
set -eo pipefail  # 严格错误检查

version=${1:-1.0.0}
failed=false

# 启动所有任务并记录 PID
pids=()
docker build -f ./assets-rpc/Dockerfile -t assets-rpc:$version . & pids+=($!)
docker build -f ./login-rpc/Dockerfile -t login-rpc:$version  . & pids+=($!)
docker build -f ./assets-api/Dockerfile -t assets-api:$version . & pids+=($!)

# 检查每个任务状态
for pid in "${pids[@]}"; do
    if ! wait "$pid"; then
        echo "镜像构建失败！PID: $pid"
        failed=true
    fi
done

if $failed; then
    exit 1
else
    echo "所有镜像构建成功"
fi